def permute(nums):
    res =[]
    track =[]

    def backtrack(nums,track):
        if len(track) ==len(nums):

            return res.append(track)

        for i in range(len(nums)):
            if nums[i] in track:
                continue
            track.append(nums[i])

            backtrack(nums,track)
            track.pop()

    backtrack(nums,track)
    return res

if __name__=="__main__":
    nums =[1,2,3,4]
    r = permute(nums)
    print(r)

